// 6_7.c Calculating Age Norms 

#include <stdio.h>
#include <math.h>

int main()
{
    float norms(float); /*here are the function prototypes*/
    float pcdif(float, float);
    void showit(float, float);

    int years, months;
    float height, normht;
    float age, perdif;

    /*this is the input section*/
    printf("\nHow old (in years) is this child? ");
    scanf("%d", &years);
    printf("How many months since the child's birthday? ");
    scanf("%d",&months);
    age = years + months/12.0; /*convert to total years*/
    printf("Enter the child's height (in inches): ");
    scanf("%f",&height);

    /*this is the calculations section*/
    normht = norms(age);
    perdif = pcdif(height,normht);

    /*this is the display section*/
    showit(normht,perdif);

    return 0;
}

float norms(float age)
{
    #define MINAGE 6.0
    float agedif, avght;
    agedif= age- MINAGE;
    avght =-0.25*pow(agedif,2)+3.5 *agedif +45.0;
    return (avght);
}


float pcdif(float actual, float base)
{
    return (actual-base)/base*100.0;
}

void showit(float normht, float perdif)
{
    printf("\nThe average height in inches is :%5.2f\n",normht);
    printf("The actual height deviates from the norm by: %6.2f%c\n",perdif,'%');
}
